<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript" src="<%= ctxPath %>/mt/js/userPopup.js"></script>

<script language="JavaScript">

  function findField(theForm, fieldName) {
    var elements = theForm.elements;
    var numElements = elements.length;
    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        return elements[elementIndex];
      }
    }
    return null;
  }

  function doPackUserEditAction(theForm, participantNameIndex, participantValue) {
    var fieldName = 'participant[' + participantNameIndex + '].name';
    var field = findField(theForm, fieldName);
    if (field != null) {
      theForm.id.value = <c:out value="${processFormView.map.packageOid}"/>;
      theForm.participantName.value = field.value;
      theForm.participantValue.value = participantValue;

      var timestamp = getTimeStamp();
      var parentFormName = "processForm";
      var parentFieldName = "participantValue";
      var popupUrl = '<html-el:rewrite page="/mt/userSearchPopup.do"/>' + '?timestamp=' + timestamp +
                     '&parentFormName=' + parentFormName + 
                     '&parentFieldName=' + parentFieldName + 
                     '&userAlias=' + participantValue + '&executeSearch=true';

      var windowName = parentFormName + parentFieldName;
      var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
      var popupWindow = window.open(popupUrl, windowName, windowFeatures);
      if ( popupWindow != null) {
        if( popupWindow.opener == null) {
          popupWindow.opener = self;
        }
      }
      popupWindow.focus();
    }
    return true;
  }

  function setUserAlias(formName, fieldName, fieldValue) {
    var thisForm = document.forms[formName];
    var elements = thisForm.elements;
    var numElements = elements.length;
    var field;

    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        field = elements[elementIndex];
        break;
      }
    }
    field.value = fieldValue;

    thisForm.forwardPage.value = '<html-el:rewrite page="/bp/packageView.do"/>';
    thisForm.action = '<html-el:rewrite page="/bp/packageUserSave.do"/>'; 
    thisForm.submit();
  }
  
  function doPackGroupEditAction(theForm, participantNameIndex, participantValue) {
    var fieldName = 'participant[' + participantNameIndex + '].name';
    var field = findField(theForm, fieldName);
    if (field != null) {
      theForm.id.value = <c:out value="${processFormView.map.packageOid}"/>;
      theForm.participantName.value = field.value;
      theForm.participantValue.value = participantValue;
      theForm.forwardPage.value = '<c:url value="/bp/packageView.do"/>';
      theForm.action = '<c:url value="/bp/packageGroupView.do"/>';
      theForm.submit();
    }
    return true;
  }

</SCRIPT>

<% 
  java.util.HashMap map = new java.util.HashMap();
  String procOid = request.getParameter("processOid"); 
  if (procOid != null && procOid.length() > 0) {
    map.put("processOid", procOid);
  }
  else {
    map.put("processOid", "-1");
  }
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<c:set var="editImg">
<img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>">
</c:set>
<c:set var="individualImg">
<img src="<%= ctxPath %>/bp/images/icons/individual.gif" border="0" alt="<bean:message key="image.alt.individual" bundle="bp.messages"/>" title="<bean:message key="image.alt.individual" bundle="bp.messages"/>">
</c:set>
<c:set var="groupImg">
<img src="<%= ctxPath %>/bp/images/icons/group.gif" border="0" alt="<bean:message key="image.alt.group" bundle="bp.messages"/>" title="<bean:message key="image.alt.group" bundle="bp.messages"/>">
</c:set>

<html-el:form action="/bp/processEdit.do">
<html-el:hidden name="processForm" property="processOid"/>
<html-el:hidden name="processForm" property="description"/>
<html-el:hidden name="processForm" property="online"/>
<html-el:hidden name="processForm" property="managerAlias"/>
<html-el:hidden name="processForm" property="categoryOid"/>
<html-el:hidden name="processForm" property="duration"/>
<html-el:hidden name="processForm" property="durationType"/>
<html-el:hidden name="processForm" property="priority"/>
<input type="hidden" name="id"/>
<input type="hidden" name="forwardPage"/>
<input type="hidden" name="participantName"/>
<input type="hidden" name="participantValue"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle"><c:out value="${processFormView.map.name}"/></div>
      <div class="errorMessage"><html-el:errors bundle="bp.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>
      <logic:present name="processSubprocessPath" scope="session">
        <logic:greaterThan name="processSubprocessPath" property="processOid" value="0">
          <div class="breadcrumb">
            <html-el:link page="/bp/processSubprocessView.do" paramId="processOid" paramName="processSubprocessPath" paramProperty="processOid">
              <c:out value="${processSubprocessPath.map.processName}"/>
            </html-el:link>
            <logic:iterate id="subprocess" name="processSubprocessPath" property="subprocesses" indexId="i">
              &nbsp;<bean:message key="bp.process.taskSeparator" bundle="bp.messages"/>&nbsp;
              <logic:equal name="subprocess" property="lastone" value="false">
                <html-el:link page="/bp/processSubprocessTaskView.do" name="subprocess" property="parameterTaskMap">
                  <c:out value="${subprocess.map.number}"/>:
                  <c:out value="${subprocess.map.friendlyName}"/>
                </html-el:link>
                &nbsp;<bean:message key="bp.process.taskSeparator" bundle="bp.messages"/>&nbsp;
                <html-el:link page="/bp/processSubprocessView.do" name="subprocess" property="parameterMap">
                  <c:out value="${subprocess.map.subprocessName}"/>
                </html-el:link>
              </logic:equal>
              <logic:equal name="subprocess" property="lastone" value="true">
                <html-el:link page="/bp/processSubprocessTaskView.do" name="subprocess" property="parameterTaskMap">
                  <c:out value="${subprocess.map.number}"/>:
                  <c:out value="${subprocess.map.friendlyName}"/>
                </html-el:link>
                &nbsp;<bean:message key="bp.process.taskSeparator" bundle="bp.messages"/>&nbsp;
                <c:out value="${subprocess.map.subprocessName}"/>
              </logic:equal>
            </logic:iterate>
          </div>
        </logic:greaterThan>
      </logic:present>
      <div class="pageSubtitle">
        <span class="left"><bean:message key="bp.process.processView.information" bundle="bp.messages"/></span>
        <span class="right">
          <input type="submit" class="titleButton" value="<bean:message key="button.edit" bundle="bp.messages"/>">
        </span>
      </div> 
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Process summary">
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processName" bundle="bp.messages"/></td>
          <td class="labelField" width="70%"><c:out value="${processFormView.map.name}"/></td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.packageName" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <html-el:link page="/bp/packageView.do" paramId="id" paramName="processFormView" paramProperty="packageOid">
              <c:out value="${processFormView.map.packageName}"/>
            </html-el:link>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processView.description" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <c:out value="${processForm.map.description}" escapeXml="false"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processStatus" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <logic:equal name="processFormView" property="status" value="0">
              <bean:message key="bp.process.status.inDeployment" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processFormView" property="status" value="1">
              <logic:equal name="processForm" property="online" value="true">
                <bean:message key="bp.process.status.online" bundle="bp.messages"/>
              </logic:equal>
              <logic:equal name="processForm" property="online" value="false">
                <bean:message key="bp.process.status.offline" bundle="bp.messages"/>
              </logic:equal>
            </logic:equal>
            <logic:equal name="processFormView" property="status" value="2">
              <bean:message key="bp.process.status.error" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processFormView" property="status" value="3">
              <bean:message key="bp.process.status.toBeConfigured" bundle="bp.messages"/>
            </logic:equal>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processManager" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <logic:notEmpty name="processFormView" property="managerFullName">
              <c:out value="${processFormView.map.managerFullName}"/>
            </logic:notEmpty>
            <logic:empty name="processFormView" property="managerFullName">
              &nbsp;
            </logic:empty>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processView.categoryPath" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <logic:empty name="processFormView" property="paths">
              <bean:message key="bp.process.processView.notCategorized" bundle="bp.messages"/>
            </logic:empty>
            <logic:notEmpty name="processFormView" property="paths">
              <bean:message key="bp.process.processBrowse.rootCategory" bundle="bp.messages"/>
              <logic:iterate id="path" name="processFormView" property="paths" indexId="i">
                &nbsp;<bean:message key="bp.process.pathSeparator" bundle="bp.messages"/>&nbsp;
                <c:out value="${path.map.name}"/>
              </logic:iterate>
            </logic:notEmpty>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processView.estimatedDuration" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            
            <logic:equal name="processForm" property="durationType" value="0">
              <c:out value="${processForm.map.duration}"/>&nbsp;<bean:message key="bp.process.workingHours" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="durationType" value="1">
              <c:out value="${processForm.map.duration}"/>&nbsp;<bean:message key="bp.process.clockHours" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="durationType" value="2">
              <c:out value="${processForm.map.duration}"/>&nbsp;<bean:message key="bp.process.workingDays" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="durationType" value="3">
              <c:out value="${processForm.map.duration}"/>&nbsp;<bean:message key="bp.process.calendarDays" bundle="bp.messages"/>
            </logic:equal>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processView.priority" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <logic:equal name="processForm" property="priority" value="0">
              <bean:message key="bp.process.processView.priority.critical" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="priority" value="1">
              <bean:message key="bp.process.processView.priority.high" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="priority" value="2">
              <bean:message key="bp.process.processView.priority.medium" bundle="bp.messages"/>
            </logic:equal>
            <logic:equal name="processForm" property="priority" value="3">
              <bean:message key="bp.process.processView.priority.low" bundle="bp.messages"/>
            </logic:equal>
          </td>
        </tr>
        <tr> 
          <td class="label" width="30%"><bean:message key="bp.process.processView.version" bundle="bp.messages"/></td>
          <td class="labelField" width="70%">
            <c:out value="${processFormView.map.version}"/>
          </td>
        </tr>
      </table>
      <logic:notEmpty name="processFormView" property="delegations">
        <div class="pageSubtitle">
          <span class="left"><bean:message key="bp.user.userDelegationListBody.pageSubtitle.processManager" bundle="bp.messages"/></span>
          <span class="right">&nbsp;</span>
        </div> 
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Delegation table" width="100%">
          <tr class="listHeader">
            <th id="DelegatorFullName" align="left">
              <bean:message key="bp.user.userDelegationListBody.header.from" bundle="bp.messages"/>
            </th>
            <th id="DelegateFullName" align="left">
              <bean:message key="bp.user.userDelegationListBody.header.delegateTo" bundle="bp.messages"/>
            </th>
            <th id="StartDate" align="left">
              <bean:message key="bp.user.userDelegationListBody.header.start" bundle="bp.messages"/>
            </th>
            <th id="EndDate" align="left">
              <bean:message key="bp.user.userDelegationListBody.header.end" bundle="bp.messages"/>
            </th>
          </tr>
            <logic:iterate id="delegation" name="processFormView" property="delegations" indexId="i">
              <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
                <td headers="DelegatorFullName">
                  <c:out value="${delegation.map.delegatorFullName}"/>
                </td>
                <td headers="DelegateFullName">
                  <c:out value="${delegation.map.delegateFullName}"/>
                </td>
                <td headers="StartDate">
                  <bean:write name="delegation" property="startDate" formatKey="format.datetime.short" bundle="mc.messages"/>
                </td>
                <td headers="EndDate">
                  <bean:write name="delegation" property="endDate" formatKey="format.datetime.short" bundle="mc.messages"/>
                </td>
              </tr>
            </logic:iterate>
        </table>
      </logic:notEmpty>
      <div class="pageSubtitle">
        <span class="left"><bean:message key="bp.package.participantList" bundle="bp.messages"/></span>
        <span class="right">&nbsp;</span>
      </div> 
      <div class="pageInstructions">(*) <bean:message key="bp.package.detail.instruction" bundle="bp.messages"/></div>
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left">
            <bean:message key="bp.package.participantName" bundle="bp.messages"/>
          </th>
          <th id="Description" align="left">
            <bean:message key="bp.package.participantDescription" bundle="bp.messages"/>
          </th>
          <th id="Identities" align="left">
            <bean:message key="bp.package.participantIdentities" bundle="bp.messages"/>
          </th>
          <th id="Actions" align="left" nowrap>
            <bean:message key="header.actions" bundle="bp.messages"/>
          </th>
        </tr>
        <logic:notEmpty name="processFormView" property="participants">
          <logic:iterate id="participant" name="processFormView" property="participants" indexId="i">
            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td headers="Name">
                <logic:equal name="participant" property="type" value="0">
                  <c:out value='${individualImg}' escapeXml="false"/>
                </logic:equal>
                <logic:equal name="participant" property="type" value="1">
                  <c:out value='${groupImg}' escapeXml="false"/>
                </logic:equal>
                &nbsp;<c:out value="${participant.map.name}"/>
              </td>
              <td headers="Description">
                <c:out value="${participant.map.description}"/>
              </td>
              <td headers="Identities">
                <logic:notEmpty name="participant" property="values">
                  <bean:define id="valuesCountId" name="participant" property="valuesCount"/>
                  <% Integer valuesCountInt = (Integer)pageContext.getAttribute("valuesCountId"); %>
                  <logic:iterate id="onevalue" name="participant" property="values" indexId="j">
                    <% if (j.intValue() < valuesCountInt.intValue() - 1) { %>
                      <logic:equal name="onevalue" property="valueValid" value="0">
                        <c:out value="${onevalue.map.value}"/><bean:message key="bp.package.detail.invalidSymbol" bundle="bp.messages"/><bean:message key="bp.process.processView.identitySeparator" bundle="bp.messages"/>
                      </logic:equal>
                      <logic:equal name="onevalue" property="valueValid" value="1">
                        <c:out value="${onevalue.map.value}"/><bean:message key="bp.process.processView.identitySeparator" bundle="bp.messages"/>
                      </logic:equal>
                    <% } else { %>
                      <logic:equal name="onevalue" property="valueValid" value="0">
                        <c:out value="${onevalue.map.value}"/><bean:message key="bp.package.detail.invalidSymbol" bundle="bp.messages"/>
                      </logic:equal>
                      <logic:equal name="onevalue" property="valueValid" value="1">
                        <c:out value="${onevalue.map.value}"/>
                      </logic:equal>
                    <% } %>
                  </logic:iterate>
                </logic:notEmpty>
                <logic:empty name="participant" property="values">
                  &nbsp;
                </logic:empty>
              </td>
              <td nowrap align="left" headers="Actions">
                <html-el:hidden name='participant' property='name' indexed='true'/>
                <logic:equal name="participant" property="type" value="0">
                  <a href="#" onclick='javascript:doPackUserEditAction(document.processForm, <%=i%>, "<c:out value="${participant.map.valuesString}"/>")'><c:out value='${editImg}' escapeXml="false"/></a>
                </logic:equal>
                <logic:notEqual name="participant" property="type" value="0">
                  <a href="#" onclick='javascript:doPackGroupEditAction(document.processForm, <%=i%>, "<c:out value="${participant.map.valuesString}"/>")'><c:out value='${editImg}' escapeXml="false"/></a>
                 </logic:notEqual>
              </td>
            </tr>
          </logic:iterate>
        </logic:notEmpty>
      </table>
    </td>
  </tr>
</table>
</html-el:form>
